}
Terminate a code block or command
TLDR
View documentation for the { keyword
SYNOPSIS
As a shell metacharacter, '}' does not have a command synopsis in the traditional sense (like ls). Instead, its synopsis describes its usage within common shell constructs:
1. Command Grouping:
{ command_list; }
{ command_list; } [redirections]
2. Brace Expansion:
prefix{string1,string2,...}suffix
prefix{start..end}suffix
prefix{start..end..increment}suffix
PARAMETERS
N/A
The '}' character is a shell metacharacter and does not accept parameters or options in the conventional sense of a command. Its behavior is context-dependent, dictated by its position within shell syntax.
DESCRIPTION
The '}' character is a fundamental shell metacharacter in Linux, primarily serving two distinct but crucial roles within shell scripting and command-line interactions.
Its most common use is as the closing delimiter for command grouping. When enclosed within curly braces (e.g., { command_list; }), a series of commands is treated as a single compound command. This grouping allows you to apply redirections (like >, <, | ) or execute background processes to the entire block of commands, rather than just the last one. It's often used when the commands need to execute in the current shell environment, unlike subshells created by parentheses (()).
The second significant role of '}' is in brace expansion, a feature supported by shells like Bash, Zsh, and Ksh. This allows for the generation of arbitrary strings based on specific patterns. It can create sequences from a comma-separated list of items (e.g., {foo,bar} expands to 'foo bar') or numeric/alphabetic ranges (e.g., {1..3} expands to '1 2 3'). Brace expansion occurs very early in the shell's parsing process, before other expansions like variable or command substitution.
CAVEATS
When used for command grouping ({ ... }), a semicolon (;) or newline must precede the closing '}' unless it's the very first token after the opening '{'. For example, { command1; command2; } is valid, but { command1; command2 } is often a syntax error without a trailing semicolon or newline. This is because '{' and '}' are treated as reserved words, and a semicolon or newline is needed to terminate the preceding command list.
Brace expansion patterns are not quoted and are expanded by the shell before filename expansion or word splitting. If brace expansion generates a large number of strings, it can lead to very long command lines, potentially exceeding system limits. Also, the order of expansion is generally left-to-right for lists, and increasing for numeric/alphabetic ranges.
HISTORY
The concept of command grouping using curly braces and brace expansion are long-standing features in Unix-like shells. Command grouping was introduced early in the development of the Bourne shell (sh) to provide a mechanism for treating a sequence of commands as a single unit, essential for redirection and control flow. Brace expansion, while not originally part of the Bourne shell, was later introduced in shells like csh (C shell) and subsequently adopted and enhanced in more modern shells such as bash (Bourne-Again SHell), ksh (Korn shell), and zsh (Z shell). Its inclusion significantly streamlined tasks involving file naming patterns and string generation, becoming a ubiquitous feature in contemporary shell scripting.